﻿using System;
using System.Web.UI.WebControls;
using System.Xml;
using System.Reflection;
using Coffee.Configuration;

namespace Coffee.ServiceLocators
{

    public delegate void BindingDelegate(DataBoundControl value, XmlNode node);

    public class BindingService : ServiceLocator<string, BindingDelegate>
    {
        public static void Initialize() 
        {
            ProvidersSection config = ProvidersSection.GetConfiguration("Coffee/BindingProviders");
            if (config != null)
            {
                foreach (KeyTypeMethodElement item in config.Providers)
                {
                    Type t = Type.GetType(item.Type);
                    MethodInfo mi = t.GetMethod(item.Method);
                    AddProvider(item.Key, (BindingDelegate)Delegate.CreateDelegate(typeof(BindingDelegate), mi));
                }
            }
        }
    }

}
